package com.xw.utils;

import com.xw.enums.ResultEnum;
import com.xw.vo.ResultVO;

/**
 * @Description: 返回工具
 * @Author: y
 * @CreateDate: 9/13/21 9:28 AM
 * @Version: 1.0
 */
public class ResultVOUtil {

    public static ResultVO<Object> success() {
        ResultVO<Object> resultVO = new ResultVO<>();
        resultVO.setCode(ResultEnum.SUCCESS.getCode());
        resultVO.setMsg(ResultEnum.SUCCESS.getMsg());
        return resultVO;
    }


    public static ResultVO<Object> success(Object o, String msg) {
        return success().setData(o).setMsg(msg);
    }

    public static ResultVO<Object> success(Object o, Long total) {
        return success().setData(o).setTotal(total);
    }

    public static ResultVO<Object> success(Object o) {
        return success().setData(o);
    }

    public static ResultVO<Object> success(String o) {
        return success().setMsg(o);
    }


    private static ResultVO<?> fail(Integer code, String msg) {
        ResultVO<?> resultVO = new ResultVO<>();
        resultVO.setMsg(msg);
        resultVO.setCode(code);
        return resultVO;
    }

    public static ResultVO<?> fail() {
        ResultVO<?> resultVO = new ResultVO<>();
        resultVO.setMsg(ResultEnum.FAIL.getMsg());
        resultVO.setCode(ResultEnum.FAIL.getCode());
        return resultVO;
    }

    public static ResultVO<?> fail(ResultEnum resultEnum) {
        ResultVO<?> resultVO = new ResultVO<>();
        resultVO.setMsg(resultEnum.getMsg());
        resultVO.setCode(resultEnum.getCode());
        return resultVO;
    }

    public static ResultVO<?> fail(ResultEnum resultEnum, String msg) {
        ResultVO<?> resultVO = new ResultVO<>();
        resultVO.setMsg(resultEnum.getMsg() + ":" + msg);
        resultVO.setCode(resultEnum.getCode());
        return resultVO;
    }
//    public static ResultVO<?> error(SystemSettingEnum systemSettingEnum) {
//        return error(Integer.valueOf(systemSettingEnum.getCode()), systemSettingEnum.getMsg());
//    }

    public static ResultVO<?> fail(String msg) {
        return fail(ResultEnum.FAIL.getCode(), msg);
    }
}